﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using QLPMT_DTO;

namespace QLPMT_DAO
{
   public class PhieuKhamDAO
    {
       DataProvider provider;
       public PhieuKhamDAO()
       {
           provider = new DataProvider();
       }
       // Phieu Kham theo cung ngay
       public List<PhieuKham> DanhSachPhieuKhamCungNgay(DateTime ngay)
       {
           provider.Connect();
           string sql = "select PhieuKham.* from PhieuKham,KhamBenh where PhieuKham.MaKhamBenh=KhamBenh.MaKhamBenh and  datediff(dd,ngaykham,'"+ngay+"')=0";
           SqlDataReader reader = provider.ExecuteReader(sql);
           List<PhieuKham> list = new List<PhieuKham>();
           while (reader.Read())
           {
               string ma = reader.GetString(0);
               string makhambenh = reader.GetString(1);
               string trieuchung = reader.GetString(2);
               PhieuKham dto = new PhieuKham(ma, makhambenh, trieuchung);
               list.Add(dto);
           }
           provider.Disconnect();
           return list;
       }
       // Danh Sách phiếu khám bệnh
       public List<PhieuKham> DanhSachPhieuKham()
       {
           List<PhieuKham> list = new List<PhieuKham>();
           provider.Connect();
           string sql = "select * from PhieuKham";
          SqlDataReader reader=provider.ExecuteReader(sql);
           while (reader.Read())
           {
               string maphieu = reader.GetString(0);
               string makhambenh = reader.GetString(1);
               string trieuchung = reader.GetString(2);
               PhieuKham dto = new PhieuKham(maphieu, makhambenh, trieuchung);
               list.Add(dto);
           }
           provider.Disconnect();
           return list;
       }
       // Them 1 phieu khám benh 
       public void InsertPhieuKham( PhieuKham dto)
       {
           provider.Connect();
           string sql = "Insert into PhieuKham(MaPhieuKham,MaKhamBenh,TrieuChung) values('"+dto.Maphieukham+"','"+dto.Makhambenh+"','"+dto.Trieuchung+"')";
           provider.ExecuteQuery(sql);
           provider.Disconnect();
       }
    }
}
